package model

import (
	"time"
)

// Database 定义数据库表的模型
type Database struct {
	ID             int64     `gorm:"primaryKey;autoIncrement;comment:自增ID" json:"id"`
	DBType         string    `gorm:"type:varchar(12);not null;comment:数据库类型名称 MySQL | PostgreSQL" json:"db_type"`
	PhysicalName   string    `gorm:"type:varchar(128);not null;comment:物理库名称，存在分片库则用 _0, _1 结尾" json:"physical_name"`
	LogicalName    string    `gorm:"type:varchar(128);not null;comment:逻辑库名称" json:"logical_name"`
	MaxStorage     *int      `gorm:"comment:最大存储空间" json:"max_storage"`
	MaxTableCounts *int      `gorm:"comment:最大表数量" json:"max_table_counts"`
	MaxTPS         *int      `gorm:"comment:最大TPS" json:"max_tps"`
	MaxQPS         *int      `gorm:"comment:最大QPS" json:"max_qps"`
	ClusterID      *int      `gorm:"comment:集群ID" json:"cluster_id"`
	Cluster        *Cluster  `gorm:"foreignKey:ClusterID" json:"cluster"`
	Env            string    `gorm:"type:varchar(12);not null;comment:环境" json:"env"`
	IsShard        bool      `gorm:"type:boolean;not null;comment:是否分片库" json:"is_shard"`
	ShardNum       *int      `gorm:"comment:分片库数量" json:"shard_num"`
	Unit           *string   `gorm:"type:varchar(50);comment:机房标识：SHANGHAI | BEIJING" json:"unit"`
	AppName        string    `gorm:"type:varchar(64);not null;comment:应用名称" json:"app_name"`
	Level          *string   `gorm:"type:varchar(12);comment:数据库等级 " json:"level"`
	BusinessOne    string    `gorm:"type:varchar(64);not null;comment:一级业务线名称" json:"business_one"`
	BusinessTwo    string    `gorm:"type:varchar(64);not null;comment:二级业务线名称" json:"business_two"`
	Status         string    `gorm:"type:varchar(12);not null;default:online;comment:状态，online/offline/discard" json:"status"`
	Remark         string    `gorm:"type:varchar(255);comment:备注" json:"remark"`
	CreateTime     time.Time `gorm:"autoCreateTime;comment:创建时间" json:"create_time"`
	UpdateTime     time.Time `gorm:"autoUpdateTime;comment:更新时间" json:"update_time"`
	IsDelete       bool      `gorm:"type:boolean;default:false;comment:逻辑删除标记，FALSE表示未删除，TRUE表示已删除" json:"is_delete"`
}

// TableName 指定表名
func (Database) TableName() string {
	return "database"
}

type DatabaseListRequest struct {
	DBType       string `form:"db_type" json:"db_type"`
	PhysicalName string `form:"physical_name" json:"physical_name"`
	LogicalName  string `form:"logical_name" json:"logical_name"`
	ClusterID    *int   `form:"cluster_id" json:"cluster_id"`
	Env          string `form:"env" json:"env"`
	IsShard      bool   `form:"is_shard" json:"is_shard"`
	AppName      string `form:"app_name" json:"app_name"`
	BusinessOne  string `form:"business_one" json:"business_one"`
	BusinessTwo  string `form:"business_two" json:"business_two"`
	Status       string `form:"status" json:"status"`
	Search       string `json:"search"`
	Page         int64  `form:"page" json:"page" default:"1"`
	PageSize     int64  `form:"page_size" json:"page_size" default:"10"`
	ShowCluster  bool   `form:"show_cluster" json:"show_cluster"`
}

type DatabaseListResponse struct {
	Count    uint64      `json:"count"`
	Records  []*Database `json:"records"`
	Page     int64       `json:"page"`
	PageSize int64       `json:"page_size"`
}
